package cn.zzuli.loginandregister;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class LoginActivity extends AppCompatActivity {
    WebView webView;
    AlertDialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.activity_login );

        //接收传递来的url参数
        String url=getIntent ().getStringExtra ( "link" );

        webView=findViewById ( R.id.wv_login );
        webView.setWebViewClient ( new WebViewClient (){
            //设置在webView点击打开的新网页在当前页面展示，而不跳转到新的浏览器中
            public boolean shouldOverrideUrlLoading(WebView view, String url){
                view.loadUrl ( url );
                return true;
            }
        } );
        webView.loadUrl ( url );//调用loadUrl方法为webView加入链接
    }
    public void onBackPressed() {
        //super.onBackPressed ();
        dialog = new AlertDialog.Builder (this).setTitle ( "提示" )
                .setMessage ( "你确认要退出吗？" )
                .setIcon ( R.mipmap.ic_launcher )
                .setPositiveButton ( "确定",new DialogInterface.OnClickListener(){
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish ();
                        //Toast.makeText (MainActivity.this,"再按一次退出！",Toast.LENGTH_SHORT).show ();
                    }
                } )
                .setNegativeButton ( "取消",null )
                .create();
        dialog.show();
        //Toast.makeText ( MainActivity.this,"hello world", Toast.LENGTH_SHORT ).show();
    }
}